import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem('Authorization')
      ? localStorage.getItem('Authorization')
      : '',
    userInfo: localStorage.getItem('userInfo')
      ? JSON.parse(localStorage.getItem('userInfo'))
      : ''
  },
  getters: {
    getToken(state) {
      return state.token
    },
    getUserInfo(state) {
      return state.userInfo
    }
  },
  mutations: {
    setToken(state, value) {
      state.token = value
      localStorage.setItem('Authorization', value)
    },
    deleteToken(state) {
      state.token = ''
      localStorage.removeItem('Authorization')
    },
    setUser(state, value) {
      state.userInfo = value
      localStorage.setItem('userInfo', JSON.stringify(value))
    },
    deleteUser(state) {
      state.userInfo = ''
      localStorage.removeItem('userInfo')
    }
  },
  actions: {},
  modules: {}
})
